<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryForm" :model="queryParams" label-width="80px">
          <el-row>
            <el-col :span="5">
              <el-form-item label="门店" prop="storeId">
                <el-select
                  v-model="queryParams.storeId"
                  placeholder="请选择"
                  filterable
                >
                  <el-option
                    v-for="(item, index) in $store.state.user.stores"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="时间" prop="time">
                <el-date-picker
                  v-model="queryParams.time"
                  type="monthrange"
                  range-separator="至"
                  start-placeholder="开始月份"
                  end-placeholder="结束月份"
                  value-format="yyyy-MM"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>

    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">门店充值消费（月）</div>
        <div class="op_right">
          <el-button
            @click="handleExport"
            :loading="exportLoading"
            class="repeat"
            v-hasPermi="['customer:account:total:page:moon:exl']"
            >导出</el-button
          >
        </div>
      </div>

      <div class="table_list">
        <el-table
          :data="RechargeMonthList"
          stripe
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column prop="storeName" label="门店名称" width="180px">
          </el-table-column>
          <el-table-column prop="accountTotalMoon" label="统计月份">
          </el-table-column>
          <el-table-column
            prop="principalMoneyResidue"
            label="本金剩余"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="giveMoneyResidue"
            label="赠送金剩余"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="extraMoneyResidue"
            label="额外赠送金剩余"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="principalMoneyBlocked"
            label="本金冻结剩余"
            width="150px"
          >
          </el-table-column>
          <el-table-column
            prop="giveMoneyBlocked"
            label="赠送金冻结剩余"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="extraMoneyBlocked"
            label="额外赠送金冻结剩余"
            width="150px"
          >
          </el-table-column>

          <el-table-column
            prop="principalMoneyAddNew"
            label="本金充值(新)"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="giveMoneyAddNew"
            label="赠送金充值(新)"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="extraMoneyAdd"
            label="额外赠送金充值(新)"
            width="150px"
          >
          </el-table-column>

          <el-table-column
            prop="principalMoneyNew"
            label="本金消耗(新)"
            width="120px"
          >
          </el-table-column>

          <el-table-column
            prop="giveMoneyNew"
            label="赠送金消耗(新)"
            width="120px"
          >
          </el-table-column>

          <el-table-column
            prop="extraMoneyNew"
            label="额外赠送金消耗(新)"
            width="150px"
          >
          </el-table-column>

          <el-table-column
            prop="principalMoneyAdd"
            label="本金充值(老)"
            width="120px"
          >
          </el-table-column>

          <el-table-column
            prop="giveMoneyAdd"
            label="赠送金充值(老)"
            width="120px"
          >
          </el-table-column>

          <el-table-column
            prop="extraMoneyAddNew"
            label="额外赠送金充值(老)"
            width="150px"
          >
          </el-table-column>

          <el-table-column
            prop="principalMoney"
            label="本金消耗(老)"
            width="120px"
          >
          </el-table-column>

          <el-table-column
            prop="giveMoney"
            label="赠送金消耗(老)"
            width="120px"
          >
          </el-table-column>

          <el-table-column
            prop="extraMoney"
            label="额外赠送金消耗(老)"
            width="150px"
          >
          </el-table-column>

          <!-- <el-table-column
            prop="moneyAdd"
            label="充值金额(老)"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="moneySub"
            label="消耗金额(老)"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="moneyAddNew"
            label="充值金额(新)"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="moneySubNew"
            label="消耗金额(新)"
            width="120px"
          >
          </el-table-column> -->
          <el-table-column
            prop="principalMoneyTransferIn"
            label="本金转入"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="giveMoneyTransferIn"
            label="赠送金转入"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="extraMoneyTransferIn"
            label="额外赠送金转入"
            width="120px"
          >
          </el-table-column>

          <el-table-column
            prop="principalMoneyTransferOut"
            label="本金转出"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="giveMoneyTransferInOut"
            label="赠送金转出"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="extraMoneyTransferInOut"
            label="额外赠送金转出"
            width="120px"
          >
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
import {
  getStoreUser,
  getStoreInfoList,
  getRechargeMonth,
} from "@/api/bpm/handmade";
import { getAccountMoonExl } from "@/api/bpm/excle";
export default {
  name: "Storeadminrechargemonth",

  data() {
    return {
      RechargeMonthList: [], // 技师手工
      loading: false,
      exportLoading: false,
      queryTypeOptions: [],
      value: "",
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        storeId: "",
        time: [],
      },
      total: 0,
    };
  },

  mounted() {},

  created() {
    this.getList();
    this.getStorelist();
  },

  methods: {
    handleExport() {
      this.$modal
        .confirm("是否确认导出报表数据?")
        .then(() => {
          this.exportLoading = true;
          let queryParams = JSON.parse(JSON.stringify(this.queryParams));

          if (!!this.queryParams.time) {
            queryParams.startMoon = this.queryParams.time[0];
            queryParams.endMoon = this.queryParams.time[1];
          }
          delete queryParams.time;
          return getAccountMoonExl(queryParams);
        })
        .then((response) => {
          this.$download.excel(response, "门店充值消费（月）");
          this.exportLoading = false;
        })
        .catch(() => {
          this.exportLoading = false;
        });
    },
    getUsers() {
      this.queryParams.userId = "";
      getStoreUser({
        filterUser: "N",
        storeId: this.queryParams.storeId,
      })
        .then((res) => {
          const { code, data } = res;
          if (code === 0) {
            this.usersList = data;
          }
        })
        .catch((err) => {});
    },

    // 门店
    getStorelist() {
      getStoreInfoList({})
        .then((res) => {
          const { code, data } = res;
          if (code === 0) {
            this.queryTypeOptions = data;
          }
        })
        .catch((err) => {});
    },

    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryForm");
      this.handleQuery();
    },

    // 表单重置
    resetFormData(formName) {
      console.log(this.$refs[formName]);
      this.$refs[formName].resetFields();
    },

    //
    getList() {
      this.loading = true;
      let queryParams = JSON.parse(JSON.stringify(this.queryParams));

      if (!!this.queryParams.time) {
        queryParams.startMoon = this.queryParams.time[0];
        queryParams.endMoon = this.queryParams.time[1];
        queryParams.time = [];
      }

      getRechargeMonth(queryParams)
        .then((res) => {
          // console.log(res);
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.RechargeMonthList = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.goodTop {
  width: 100%;
  height: 48px;
  background: #ffffff;
  display: flex;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.6);
  line-height: 48px;
  padding-left: 16px;
  .good_list {
    margin-right: 32px;
  }

  .good_active {
    color: #0052d9;
    border-bottom: 1px solid #0052d9;
  }
}

.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}

.Order_box {
  display: flex;
  margin-left: -50px;
  .select_ipt {
    width: 130px;
    margin-right: 10px;
  }
}

.pay_ipt {
  margin-left: 50px;
}

.order_ipt {
  margin-left: -120px;
}
</style>
